import Vue from 'vue'
import iView from 'iview'
import VueI18n from 'vue-i18n'
import langZhCn from 'iview/dist/locale/zh-CN'
import langEnUs from 'iview/dist/locale/en-US'
import customlangZhCn from './lang/zh-CN'
import customlangEnUs from './lang/en-US'

Vue.use(VueI18n)
Vue.use(iView)

// 自动根据浏览器语言设置语言
const navigatorLang = navigator.language
const localLang = (navigatorLang === 'zh-CN' || navigatorLang === 'en-US') ? navigatorLang : false
let lang = window.localStorage.lang || localLang || 'zh-CN'

Vue.locale = () => {}
const messages = {
  en: Object.assign({}, langZhCn, customlangZhCn),
  zh: Object.assign({}, langEnUs, customlangEnUs)
}
// Create VueI18n instance with options
const i18n = new VueI18n({
  locale: lang, // set locale
  messages // set locale messages
})

export default i18n
